package com.kaiwukj.android.ufamily.mvp.ui.page.home;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.FriendRecoResult;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class FriendRecommendAdapter extends BaseQuickAdapter<FriendRecoResult, BaseViewHolder> {
    public FriendRecommendAdapter() {
        this(new ArrayList<>());
    }

    public FriendRecommendAdapter(List<FriendRecoResult> data) {
        super(R.layout.item_home_friend_recommend, data);
        addChildClickViewIds(R.id.btn_attention);
    }

    public void postAttention(int userId) {
        for (int i = 0; i < getData().size(); i++) {
            if (userId == getData().get(i).getUserId()) {
                removeAt(i);
                break;
            }
        }
    }

    @Override
    protected void convert(@NotNull BaseViewHolder helper, FriendRecoResult item) {
        if (item.isBoy()) {//男
            helper.setVisible(R.id.container_girl, false);
            helper.setVisible(R.id.container_boy, true);
        } else {
            helper.setVisible(R.id.container_girl, true);
            helper.setVisible(R.id.container_boy, false);
        }
        helper.setText(R.id.tv_user_name, item.getNickName());
        ImageView ivAvatar = helper.getView(R.id.iv_avatar);
        Glide.with(getContext())
                .load(item.getHeadImg())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(ivAvatar);
    }
}
